var parameter= "";
$(function(){
	Chart.defaults.global.defaultFontColor = '#fff';
	var routes =GetQueryString("route");
	var routename=decodeURIComponent(window.atob(routes));
	$(".alltitle").html(routename);
	parameter= {"startTime":"2017-01-01","service":routename};
	parameter2= {"startTime":"2017-01","service":routename}
	//前十大货物
	goodsTop10();
	//前十大客户
	customerTop10();
	//航线贡献值，港口
	portContribution();
	//航线贡献值，月度
	monthContribution();
	//航线贡献值，月TEU平均运价
	monthAverageFreightTEU();
})
//航线贡献值，月TEU平均运价
var monthAverageFreightTEU = function(){
	$.ajax({
	    type: "post",
	    async: true,
	    url: "/enReport/monthAverageFreightTEU",
	    data: parameter2,
	    dataType: "json",
	    success: function(data){
	    	var labels5=[];
	    	var data5=[];
	    	for(var i=0; i<data.length;i++){
	    		labels5.push(data[i].month);
	    		data5.push(data[i].avgyj);
	    	}
	     	var route5 = document.getElementById('route_5').getContext('2d');	
			var myChartroute5 = new Chart(route5, {
				type: 'line',
				data: {
					labels: labels5,
					datasets: [{
						label: "数据一",
						borderWidth: '3',
						backgroundColor: "rgba(94,151,200,0.5)",
						borderColor: "rgba(94,151,200,1)",
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data: data5
					}]
				},
				options: {
					maintainAspectRatio: true,
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
		}
	})
}
//航线贡献值，月度
var monthContribution = function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/monthContribution",
        data: parameter,
        dataType: "json",
        success: function(data){
        	var labels4=[];
        	var data4=[];
        	for(var i=0; i<data.length;i++){
        		labels4.push(data[i].month);
        		data4.push(data[i].teu)
        	}
			var route4 = document.getElementById('route_4').getContext('2d');	
			var myChartroute4 = new Chart(route4, {
				type: 'line',
				data: {
					labels:labels4,
					datasets: [{
						label: "数据一",
						borderWidth: '3',
						backgroundColor: [
							"rgba(210,72,91,0.5)",
						],
						borderColor: [
							"rgba(210,72,91,1)",
						],
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data:data4
					}]
				},
				options: {
					maintainAspectRatio: true,
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
		}
	})
}
//航线贡献值，港口
var portContribution =function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/portContribution",
        data: parameter,
        dataType: "json",
        success: function(data){
        	var  labels3=[];
        	var   data3=[];
      		for(var i=0; i<data.length;i++){
      			labels3.push(data[i].startport)
      			data3.push(data[i].teu);
      		}
         	var route3 = document.getElementById('route_3').getContext('2d');	
			var myChartroute3 = new Chart(route3, {
				type: 'bar',
				data: {
					labels: labels3,
					datasets: [{
						label: "数据一",
						borderWidth: '3',
						backgroundColor: [
							"rgba(25,198,198,0.5)",
							"rgba(202,127,50,0.5)",
							"rgba(94,151,200,0.5)",
							"rgba(210,72,91,0.5)",
							"rgba(206,120,222,0.5)",
							"rgba(94,151,200,0.5)"
						],
						borderColor: [
							"rgba(25,198,198,1)",
							"rgba(202,127,50,1)",
							"rgba(94,151,200,1)",
							"rgba(210,72,91,1)",
							"rgba(206,120,222,1)",
							"rgba(94,151,200,1)"
						],
						pointBackgroundColor: "#46ffc3",
						pointStrokeColor: "#fff",
						data: data3
					}]
				},
				options: {
					maintainAspectRatio: true,
					scales: {
				        xAxes: [{
				            ticks: {
				            	autoSkip: false,
				            }
				        }]
				    },
					legend: {
						labels: {
							
						},
						display: false,
					},
				},
			});
		}
	})
}
//前十大客户
var customerTop10 = function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/customerTop10",
        data: parameter,
        dataType: "json",
        success: function(data){
        	var str="";
          	for(var i=0 ; i<data.length;i++){
          		str+='<li>'+
						'<p class="customername">'+data[i].customer+'</p><p class="customeracount">'+data[i].teu+'</p>'+
					'</li>'
          	}
          	$("#route_customers").html(str);
		}
	})
}
//前十大货物
var goodsTop10 = function(){
	$.ajax({
        type: "post",
        async: true,
        url: "/enReport/goodsTop10",
        data: parameter,
        dataType: "json",
        success: function(data){
        	var str="";
          	for(var i=0 ; i<data.length;i++){
          		str+='<li><p class="goodsname">'+data[i].gt+'</p><p class="goodsacount">'+data[i].teu+'</p></li>'
          	}
          	$("#route_goods").html(str);
		}
	})
}
//截取字符串
function GetQueryString(name){
 	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
 	var r = window.location.search.substr(1).match(reg);
	if(r!=null)return  unescape(r[2]); return null;
}